/**
 * Created by spatra on 14-9-8.
 */

define(function(){

	var conservationOfEnergyAndMomentum = function(arguments){
		var m1 = arguments.m1 || 1;
		var m2 = arguments.m2 || 1;
		var v1 = arguments.v1 || 0;
		var v2 = arguments.v2 || 0;


		var v1Fin = ( (m1 - m2) + 2 * m2 * v2 ) / ( m1 + m2 );
		var v2Fin = ( (m2 - m1) + 2 * m1 * v1 ) / ( m1 + m2 );

		return {
			v1Fin : v1Fin,
			v2Fin : v2Fin
		}
	};

	var resloveDistanceByVelAndAcc = function(v0, t, a){
		return v0 * t + 0.5 * a * t * t;
	};

	var resolveTimeByDistanceAndAcc = function(distance, a, v0){
		var result = MathHelper.quadraticEquations(0.5 * a, v0, -1 * distance);

		if( result !== null ){
			var t = result.x1 >= 0 ? result.x1 : result.x2;
			return t >= 0 ? t : null;
		}
		else{
			return null;
		}
	};


	return{
		conservationOfEnergyAndMomentum: conservationOfEnergyAndMomentum,
		resolveDistanceByVelAndAcc: resloveDistanceByVelAndAcc
	}
});